<template>
  <div class="app">
    <el-config-provider :locale="zhCn">
      <router-view />
    </el-config-provider>
  </div>
</template>

<script lang="ts" setup>
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import { ElNotification } from 'element-plus'
import emitter, { api_fail } from '@/emitter'
import useLoginStore from '@/store/login'
// import { onBeforeUnmount } from 'vue'

const loginStore = useLoginStore()
// emitter.emit('API:UN_AUTH', err)

// emitter.on('API:UN_AUTH', (err) => {
//   console.log(err)
// })
emitter.on(api_fail, (message, code, title) => {
  if (code === 401) {
    loginStore.logout()
  }
  loginStore.clearLoginInfo()
  ElNotification({
    title,
    message,
    type: 'error'
  })
})

// onBeforeUnmount(() => {
//   loginStore.clearLoginInfo()
//   loginStore.logout()
// })
</script>

<style lang="scss">
.app {
  width: 100vw;
  height: 100vh;
}
</style>
